package org.baicaixiaozhan.springbootwebdemo1.controller;

import org.baicaixiaozhan.springbootwebdemo1.exception.GlobalExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * DESC: 用于接收 filter 转发过来的异常, 最后由 {@link GlobalExceptionHandler} 处理
 *
 * @author : baicaixiaozhan
 * @since : 2021-01-30
 */
@RestController
@RequestMapping("/filter/exception")
public class FilterExceptionController {


    @RequestMapping(value = "", method = {RequestMethod.GET, RequestMethod.POST})
    public String handleFilterException(HttpServletRequest request) throws Exception {
        throw ((Exception) request.getAttribute("filter.exception"));
    }

}
